<template>
  <div class="newsinfo-container">
    <!-- 新闻头部 -->
    <h3 class="title">{{ newsInfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ newsInfo.addTime | dateFormat}}</span>
      <span>点击：{{ newsInfo.clickNum }}次</span>
    </p>

    <hr>
    <!-- 新闻内容 -->
    <div class="content" v-html="newsInfo.content"></div>

    <!-- 评论区域 -->
    <common :id="id"></common>
  </div>
</template>

<script>
import { Toast } from 'mint-ui';
import Common from '../subcomponents/common.vue';

export default {
  data() {
    return {
      id: this.$route.params.id,
      newsInfo: {}
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
      //this.$http.get('./../../../api/newsinfo.json' + this.id).then(res => {
      
      //请求前台 api 中的json 写法（莫得办法，哎！）
      this.$http.get('./../../../api/newsinfo.json').then(res => {
        if(res.body.status === 0) {
          this.newsInfo = res.body.message;
        }else {
          Toast('err');
        }
      });
    }
  },
  components: {
    'common': Common
  }
};
</script>

<style>
  .newsinfo-container {
    padding: 0 6px;
  }
  .newsinfo-container h1,
  .newsinfo-container h2 {
    font-size: 16px;
  }
  .newsinfo-container .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .newsinfo-container .subtitle {
    font-size: 13px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .newsinfo-container .content img {
    width: 100%;
  }
</style>
